﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NewsMine.DataManagers;
using NewsMine.DomainObjects;


namespace WebApp1.AdminSection
{
    public partial class Channels : System.Web.UI.Page
    {
        public Channel CurrentChannel { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (WebApp1.Models.SecurityCheckManager.IsAdminPortalEabled() == false)
            {
                Response.Write("You should be the admin....");
                return;
            }

            string selectedChannelName = Request.QueryString.Get("name");
            if (!string.IsNullOrEmpty(selectedChannelName) && !IsPostBack)
            {
                ChannelManager channelManager = new ChannelManager();


                CurrentChannel = channelManager.GetChennelByName(selectedChannelName);

                if (CurrentChannel == null)
                    CurrentChannel = new Channel();
            }
            else
                CurrentChannel = new Channel();

            if (IsPostBack)
            {

                ChannelManager channelManager = new ChannelManager();

                Channel ch = new Channel();

                ch.Name = Request.Form["Name"];
                ch.DisplayName = Request.Form["DisplayName"];
                ch.Description = Request.Form["Description"];
                ch.Language = Request.Form["Language"];
                ch.ParentChannelName = Request.Form["ParentChannelName"];
                ch.Query = Request.Form["Query"];
                ch.Domains = Request.Form["Domains"];
                ch.Categories = Request.Form["Categories"];
                ch.Tags = Request.Form["Tags"];
                ch.Rank = int.Parse(Request.Form["Rank"]);

                channelManager.ReplaceChannel(ch);

                CurrentChannel = channelManager.GetChennelByName(ch.Name);
            }
            else
            {
                //just list out all the items here.

                ListAllTheChannels();
            }
            

        }

        private void ListAllTheChannels()
        {
            
            
        }
    }
}